import 'package:flutter/material.dart';
import 'package:lai_zhan/common/model/activity/activity.dart';
import 'package:lai_zhan/common/model/userResult/user_result.dart';
import 'package:lai_zhan/common/model/shopResult/shop_result.dart';
import 'package:lai_zhan/common/model/vipResult/vip_result.dart';
import 'package:lai_zhan/widget/BaseScaffold.dart';
import 'package:lai_zhan/common/style/AppStyle.dart';
import 'package:lai_zhan/common/util/NavigatorUtil.dart';
import 'package:lai_zhan/common/net/HttpManager.dart';
import 'package:flutter_html/flutter_html.dart';
//import 'package:flutter_html_view/flutter_html_view.dart';

class ActivityPage extends StatefulWidget {

  Activity activity;


  ActivityPage({this.activity});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _ActivityPageState(activity);
  }
}

class _ActivityPageState extends State<ActivityPage> {

  Activity activity; //活动
  List<VipResult> vipResults; //vip列表
  List<ShopResult> shopResults; //开展店铺
  UserResult userResult; //发布用户
  String url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545929952560&di=43869d08b846aa15f1587c120c945f63&imgtype=0&src=http%3A%2F%2Fpic.baike.soso.com%2Fp%2F20120515%2F20120515114505-1317620601.jpg';


  _ActivityPageState(this.activity);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    vipResults = activity.vipResults;
    shopResults = activity.shopResults;
    userResult = activity.userResult;
  }

  _renderImage(){
    return new Container(
      child: FadeInImage.assetNetwork(placeholder: 'lib/images/image1.jpg', image: '')
    );
  }
  _renderVipImages(){
    return ["2","3","4","5","6"].map((str)=>
      new Image.asset('lib/images/Vip$str.png',width: AppSize.vipImageSize,height: AppSize.vipImageSize,)
    ).toList();
  }
  _renderTitle(){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      new Text('辩证唯物主义是中国共产党人的世界观和方法论',style: AppConstant.middleText,),
        new Padding(padding: EdgeInsets.all(5)),
        new Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Row(children: <Widget>[
              new Text('莱战活动中心',style: AppConstant.smallText),
              new Padding(padding: EdgeInsets.only(left: 10)),
              new Text('2019年1月1日',style:AppConstant.smallText),
            ],),
            new Row(children: <Widget>[
              new Text('发布者',style: AppConstant.smallText),
              new Padding(padding: EdgeInsets.only(left: 10)),
              new Text('王小波',style:AppConstant.smallText),
            ],),
          ],
        )
    ],);
  }

  _renderVip(){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        new Padding(padding: EdgeInsets.all(20)),
        new Image.asset('lib/images/VIP.png',width: AppSize.vipImageSize+10,),
        new Text('参与等级'),
        new Padding(padding: EdgeInsets.all(3)),
        new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children:_renderVipImages()
        ),
      ],
    );
  }

  _renderContent(){
    return new Container(
      margin: EdgeInsets.only(left: 20,right: 20,top: 50),
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          _renderImage(),
          _renderActivityContent(),
          _renderVip(),
          //_renderPromulgator(),
          _renderShops(),
        ],
      ),
    );
  }

  _renderActivityContent(){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Padding(padding: EdgeInsets.all(5)),
        new Container(margin: EdgeInsets.only(top: 5,bottom: 5),
          child: new Container(height: 1,color: Colors.black12,),
        ),
        new Text('新华社北京12月31日电 新改版的《求是》杂志2019年第1期将发表中共中央总书记、国家主席、中央军委主席习近平的重要文章《辩证唯物主义是中国共产党人的世界观和方法论》。文章指出，辩证唯物主义是中国共产党人的世界观和方法论，我们党要团结带领人民实现“两个一百年”奋斗目标、实现中华民族伟大复兴的中国梦，必须不断接受马克思主义哲学智慧的滋养，更加自觉地坚持和运用辩证唯物主义世界观和方法论，增强辩证思维、战略思维能力，努力提高解决我国改革发展基本问题的本领。文章强调，要学习掌握世界统一于物质、物质决定意识的原理，坚持从客观实际出发制定政策、推动工作；学习掌握事物矛盾运动的基本原理，不断强化问题意识，积极面对和化解前进中遇到的矛盾；学习掌握唯物辩证法的根本方法，不断增强辩证思维能力，提高驾驭复杂局面、处理复杂问题的本领；学习掌握认识和实践辩证关系的原理，坚持实践第一的观点，不断推进实践基础上的理论创新。',
          style: AppConstant.smallText,),
        new Container(margin: EdgeInsets.only(top: 5,bottom: 5),
          child: new Container(height: 1,color: Colors.black12,),
        ),
      ],
    );
  }

  _renderShops(){
    return new Column(
      children: <Widget>[
        new Padding(padding: EdgeInsets.all(20)),
        new Image.asset('lib/images/fitness_room.png',width: AppSize.vipImageSize+30,),
        new Padding(padding: EdgeInsets.all(3)),
        new Text('参与会所'),
        new Container(
          height: AppSize.shopItemHeight,
          child: new ListView.builder(
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            itemBuilder: (BuildContext context ,int index){
              return new Container();
            },itemCount: 6,),
        ),
        new Container(margin: EdgeInsets.only(top: 5,bottom: 5),
          child: new Container(height: 1,color: Colors.black12,),
        ),
        new Padding(padding: EdgeInsets.all(10)),
      ],
    );
  }


  @override
  Widget build(BuildContext context) {
//    HttpManager.instance.testPost();
//
//    new Future.delayed(new Duration(seconds: 3),(){
//      HttpManager.instance.testVip();
//    });
    // TODO: implement build
    return new BaseScaffold(title: '活动信息',
      titleColor: Color(AppColors.white),
      backgroundColor: Color(AppColors.primaryColor),
      back: (){
          NavigatorUtil.goBack(context);
      },
      body: new ListView(
        primary: false,
        padding: EdgeInsets.all(10),
        children: <Widget>[
          new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              _renderTitle(),
              Html(data: """
                <p><strong>你好</strong><br></p>
                <p><span style="font-size: 10px;">你是大傻逼</span></p>
                <p><img src="http://pic30.photophoto.cn/20140211/0005018335222016_b.png" 
                  _src="http://pic30.photophoto.cn/20140211/0005018335222016_b.png" width="50" height="100">&#8203;</p>
              """,
              customRender: (node,children){

              },
              ),
              //_renderContent(),
            ],
          )
        ],
      ),
    );
  }
}